/* 
 *  Copyright © 2011 by Rob Cash
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 * 
 * BookmarkFacade.java
 * 
 * Created on Jul 31, 2011 at 2:49:44 PM
 */
package org.robcash.apps.bookmarksync.provider.spi.delicious;

import del.icio.us.beans.Post;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import org.robcash.apps.bookmarksync.BookmarkSyncException;
import org.robcash.apps.bookmarksync.vo.Bookmark;
import org.robcash.apps.bookmarksync.vo.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Facade for a Delicious bookmark
 * @author Rob Cash
 */
public class BookmarkFacade implements Bookmark
{
    @SuppressWarnings("unused")
    private static final Logger LOG = LoggerFactory.getLogger(BookmarkFacade.class);

    private final Post post;
    private final DeliciousServiceProvider provider;

    public BookmarkFacade(final Post post, DeliciousServiceProvider provider)
    {
        this.post = post;
        this.provider = provider;
    }

    public Post getPost()
    {
        return post;
    }
    
    public String getURI()
    {
        return post.getHref();
    }

    public String getTitle()
    {
        return post.getDescription();
    }

    public String getComments()
    {
        return post.getExtended();
    }

    public Date getDateCreated()
    {
        return post.getTimeAsDate();
    }

    public Date getDateModified() throws BookmarkSyncException
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Collection<Tag> getTags() throws BookmarkSyncException
    {
        String[] textTags = post.getTagsAsArray("\\s+");
        Set<Tag> tags = new HashSet<Tag>();
        if ( textTags != null )
        {
            for( int index = 0; index < textTags.length; index++ )
            {
                tags.add(provider.getTagForName(textTags[index]));
            }
        }

        return tags;
    }

    @Override
    public String toString()
    {
        return getTitle();
    }
    
}
